﻿<UserControl x:Class="Updater.Wpf.Controls.UpdaterPopupControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:viewModels="clr-namespace:Updater.Wpf.ViewModels;assembly=Updater.Wpf"
             xmlns:Properties="clr-namespace:Updater.Wpf.Properties"
             mc:Ignorable="d" x:Name="Root"
             d:DesignHeight="32" d:DesignWidth="633"
             d:DataContext="{d:DesignInstance viewModels:UpdaterViewModel}"
             Visibility="Collapsed">
    <UserControl.Resources>
        <Storyboard x:Key="HideControlStoryboard">
            <DoubleAnimation Duration="00:00:00.4"
                             Storyboard.TargetProperty="(Control.Height)"
                             From="32"
                             To="0" />
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00.4"
                                           Duration="0"
                                           Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="ShowControlStoryboard">
            <DoubleAnimation Duration="00:00:01"
                             Storyboard.TargetProperty="(Control.Height)"
                             From="0"
                             To="32">
                <DoubleAnimation.EasingFunction>
                    <ElasticEase Oscillations="2" Springiness="6" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                           Duration="0"
                                           Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>
    <!--<UserControl.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding UserInteractionIsRequired}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource ShowControlStoryboard}" />
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <BeginStoryboard Storyboard="{DynamicResource HideControlStoryboard}" />
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>-->
    <Border Background="#D8E8FE" BorderThickness="1" BorderBrush="#6592CE">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <!-- Updates detected panel -->
            <StackPanel Orientation="Horizontal"
                        Visibility="{Binding UpdatesDetected,Converter={StaticResource BooleanToVisibilityConverter}}">
                <Image Source="pack://application:,,,/Updater.Wpf;component/Resources/Icons/arrow_turn_090_left.png"
                       Margin="6,3,2,3" />
                <Label Content="{x:Static Properties:Resources.NewVersionIsAvailable}"
                       VerticalContentAlignment="Center" Margin="3" />
                <Button Padding="3,2" Margin="3" Content="{x:Static Properties:Resources.DownloadAndInstall}"
                        Command="{Binding DownloadAndInstallUpdateCommand}" />
                <Button Padding="3,2" Margin="3" Content="{x:Static Properties:Resources.ShowDetails}"
                        Command="{Binding ShowUpdateDetailsCommand}" />
            </StackPanel>
            <!-- Update is ready to install panel -->
            <StackPanel Orientation="Horizontal"
                        Visibility="{Binding UpdateIsReadyToInstall,Converter={StaticResource BooleanToVisibilityConverter}}">
                <Image Source="pack://application:,,,/Updater.Wpf;component/Resources/Icons/exclamation_shield.png"
                       Margin="6,3,2,3" />
                <Label Content="{x:Static Properties:Resources.UpdateWillBeInstalledAfterRestart}"
                       VerticalContentAlignment="Center" Margin="3" />
                <Button Padding="3,2" Margin="3" Content="{x:Static Properties:Resources.RestartNow}"
                        Command="{Binding RestartApplicationCommand}" />
            </StackPanel>
            <!-- Error occurred panel -->
            <StackPanel Orientation="Horizontal"
                        Visibility="{Binding ErrorOccurred,Converter={StaticResource BooleanToVisibilityConverter}}">
                <Image Source="pack://application:,,,/Updater.Wpf;component/Resources/Icons/cross_circle.png"
                       Margin="6,3,2,3" />
                <Label Content="{Binding StatusText}"
                       VerticalContentAlignment="Center" Margin="3" />
                <Button Padding="3,2" Margin="3" Content="{x:Static Properties:Resources.Retry}"
                        Command="{Binding DownloadAndInstallUpdateCommand}" />
            </StackPanel>
            <Button Grid.Column="2" Padding="2" Margin="3" Command="{Binding HideCommand}">
                <Button.Style>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="False">
                                <Setter Property="Content">
                                    <Setter.Value>
                                        <Image
                                            Source="pack://application:,,,/Updater.Wpf;component/Resources/Icons/cross_unfocused.png"
                                            Width="16" Height="16" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Content">
                                    <Setter.Value>
                                        <Image
                                            Source="pack://application:,,,/Updater.Wpf;component/Resources/Icons/cross.png"
                                            Width="16" Height="16" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>
    </Border>
</UserControl>